// 设置系统缩放比，适配各分辨率(占满全屏)
export function refreshScale(): void {
  const baseWidth = document.documentElement.clientWidth;
  const baseHeight = document.documentElement.clientHeight;
  const appStyle = document.body.style;
  // const realRatio = baseWidth / baseHeight;
  // const designRatio = 32 / 15;
  const widthScaleRate = baseWidth / 1920;
  const heightScaleRate = baseHeight / 900;
  appStyle.transformOrigin = 'left top';
  appStyle.transform = `scale(${widthScaleRate},${heightScaleRate}) `;
}

//保持比例，两边留白
export function refreshScale2(designWidth = 1920, designHeight = 900): void {
  const docWidth = document.documentElement.clientWidth;
  const docHeight = document.documentElement.clientHeight;
  let widthRatio = docWidth / designWidth,
    heightRatio = docHeight / designHeight;
  let ratio = widthRatio < heightRatio ? widthRatio : heightRatio;
  document.body.setAttribute(
    'style',
    `width:${designWidth}px; height:${designHeight}px;transform:scale(${ratio}) translate(-50%,-50%);transform-origin:left top;position: fixed;top: 50%;left: 50%;`
  );
  // 应对浏览器全屏切换前后窗口因短暂滚动条问题出现未占满情况
  setTimeout(function () {
    const lateWidth = document.documentElement.clientWidth,
      lateHeight = document.documentElement.clientHeight;
    if (lateWidth === docWidth) return;

    widthRatio = lateWidth / designWidth;
    heightRatio = lateHeight / designHeight;
    ratio = widthRatio < heightRatio ? widthRatio : heightRatio;
    document.body.setAttribute(
      'style',
      `width:${designWidth}px; height:${designHeight}px;transform:scale(${ratio}) translate(-50%,-50%);transform-origin:left top;position: fixed;top: 50%;left: 50%;`
    );
  }, 0);
}
